<?php

namespace Viettrans\FrontBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\DependencyInjection\Container;

use Viettrans\FrontBundle\Form\ChoiceList\CategoriesList;
use Viettrans\FrontBundle\Form\ChoiceList\TypesList;

class AnnouncementType extends AbstractType {
    private $container;
    
    public function __construct(Container $container) {
        $this->container = $container;
    }
    
    public function buildForm(FormBuilder $builder, array $options) {
        $t = $this->container->get('translator');
		
		$myChoicesListManager = $this->container->get('my_choices_list_manager');

        $builder->add('typeId', 'choice', array(
            'label'       => $t->trans('announcement.new.fields.type'),
            'choice_list' => $myChoicesListManager->getTypes(),
            'expanded'    => true,
            'multiple'    => false,
        ));

        $builder->add('categoryId', 'choice', array(
            'label'       => $t->trans('announcement.new.fields.category'),
            'choice_list' => $myChoicesListManager->getCategories(),
            'expanded'    => false,
            'multiple'    => false,
        ));

        $builder->add('locality', 'text', array(
			'label'=> $t->trans('announcement.new.fields.locality'),
			'trim'  => true
		));
		
        $builder->add('contactName', 'text', array(
			'label'=> $t->trans('announcement.new.fields.contactName'),
			'trim'  => true
		));
		
        $builder->add('contactEmail', 'email', array(
			'label'=> $t->trans('announcement.new.fields.contactEmail'),
			'trim'  => true
		));
        
        $builder->add('contactTelephone', 'text', array(
            'label'    => $t->trans('announcement.new.fields.contactTelephone'),
            'required' => false,
			'trim'  => true
        ));
        
        $builder->add('title', 'text', array(
			'label' => $t->trans('announcement.new.fields.title'),
			'trim'  => true
		));
		
        $builder->add('description', 'textarea', array(
			'label' => $t->trans('announcement.new.fields.description'),
			'trim'  => true
		));
        
        $builder->add('price', 'text', array(
            'label' => $t->trans('announcement.new.fields.price'),
            'required' => false,
			'trim'  => true
        ));
        
        $builder->add('photo', 'file', array(
            'label'    => $t->trans('announcement.new.fields.photo'),
            'required' => false,
			'trim'     => true,
        ));
    }

    public function getDefaultOptions(array $options) {
        return array(
            'data_class'      => 'Viettrans\FrontBundle\Entity\Announcement',
            'csrf_protection' => false,
        );
    }
    
    public function getName() {
        return 'form_announcement_new';
    }
}